<template>
  <div class="header" @click="changeTheme">
    <div class="header-left" @click.stop="back"></div>
    <p class="title">{{ title }}</p>
    <div class="header-right"></div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: () => '',
      require: true
    }
  },
  data () {
    return {
      // 换肤颜色数组
      themeArr: ['theme', 'theme1', 'theme2'],
      // 换肤默认下标
      corlorIndex: 0
    }
  },
  methods: {
    // 换肤操作
    changeTheme () {
      this.corlorIndex++
      // 判断是否超出配置的颜色数据
      if (this.corlorIndex >= this.themeArr.length) {
        // 重置index
        this.corlorIndex = 0
      }
      // 添加换肤 添加自定义属性 data-theme
      document.documentElement.setAttribute('data-theme', this.themeArr[this.corlorIndex])
    },
    back () {
      window.history.back()
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/variable.scss";
@import "@/assets/css/mixin.scss";
.header {
  width: 100%;
  height: 100px;
  // 默认颜色 网易红
  @include bg_color();
  display: flex;
  justify-content: space-between;
  // position: relative;
  // z-index: 9999;
  .header-left,
  .header-right {
    width: 84px;
    height: 84px;
    margin-top: 8px;
  }
  .header-left {
    // 图片换肤
    @include bg_img("../assets/images/back");
  }
  .header-right {
    // 图片换肤
    @include bg_img("../assets/images/more");
  }
  .title {
    line-height: 100px;
    text-align: center;
    color: #fff;
    font-weight: bold;
    @include font_size($font_medium_s);
    @include no-wrap();
  }
}
</style>
